package com.example.smartcity.ui.home.adapter

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.smartcity.R
import com.example.smartcity.SmartCityApplication.Companion.context
import com.example.smartcity.ui.AcNews.NewSFlashShowActivity
import com.example.smartcity.ui.home.model.NewSRecyclerViewEntity
import kotlin.math.acos

/**
 *
 *  ANDROID STUDIO 2022
 *  @emil 2506789532@qq.com
 *  ListViewAdapter --- @ikun 2023/2/1 18:31
 **/
class NewSHotRecyclerViewAdapter(
    val HotData: List<NewSRecyclerViewEntity>
) : RecyclerView.Adapter<NewSHotRecyclerViewAdapter.HolderView>(){

    inner class HolderView(v: View) : RecyclerView.ViewHolder(v){
        // 获取控件
        val HotImageView = v.findViewById<ImageView>(R.id.newsImageView)
        val HotTitle = v.findViewById<TextView>(R.id.newsTitle)
        val HotContent = v.findViewById<TextView>(R.id.NewsContent)
        val HotComment = v.findViewById<TextView>(R.id.newsComment)
        val HotData = v.findViewById<TextView>(R.id.newsDate)

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HolderView {
        val root = LayoutInflater.from(parent.context).inflate(R.layout.listview_item_home, parent, false)
        val view = HolderView(root)
        view.itemView.setOnClickListener {
            val intent = Intent(parent.context, NewSFlashShowActivity::class.java)
            intent.putExtra("hot", HotData[view.position].newSTitle)
            parent.context.startActivity(intent)
        }

        return view
    }

    override fun getItemCount() = HotData.size

    override fun onBindViewHolder(holder: HolderView, position: Int) {
        val data = HotData[position]
        // 设置图片
        Glide.with(context)
            .load(data.imageView)
            .into(holder.HotImageView)
        // 标题
        holder.HotTitle.text = data.newSTitle
        // 内容
        holder.HotContent.text = data.NewsContent
        // 评论数
        holder.HotComment.text = data.newsComment
        // 日期
        holder.HotData.text = data.newSDate
    }
}